/*
 * MinaClientServerHandler.java
 *
 * Copyright 2012 the original author or authors(ninglong).
 *
 * Licensed under the testMina, Version 1.0 (the "License");
 *
 */
package org.geek.mina.client;

import java.util.Scanner;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;

/**   
 * <p>客户端消息处理</p>
 * @author ninglong bhd2973@qq.com   
 * @date May 2, 2012 10:24:00 PM
 * @version V1.0   
 */
public class ClientServer extends IoHandlerAdapter {

	/**
	 *接收服务发来的消息
	 */
	@Override
	public void messageReceived(IoSession session, Object message)
			throws Exception {
		String str = (String)message;
		System.out.println("服务器："+str);
		Scanner sc = new Scanner(System.in);
		String msg = sc.nextLine();
		session.write(msg);
	}

	/**
	 *客户端退出
	 */
	@Override
	public void sessionClosed(IoSession session) throws Exception {
		System.out.println("客户"+session.getRemoteAddress()+"断开连接了");
	}

	/**
	 *当客户端连接上时
	 */
	@Override
	public void sessionOpened(IoSession session) throws Exception {
		System.out.println("客户"+session.getRemoteAddress()+"连接上来了！");
	}

}
